package cn.xeblog.plugin.tools.read.error;

import cn.xeblog.plugin.util.AlertMessagesUtil;

import javax.swing.*;

/**
 * Legado接口异常
 *
 * @author LYF
 * @date 2022-07-29
 */
public class LegadoApiException extends Exception {

  /**
   * 构造
   *
   * @param errorMsg 错误消息
   */
  public LegadoApiException(String errorMsg) {
    super(errorMsg);
  }

  /**
   * 抛出异常
   * @param errorMsg 错误消息
   * @throws LegadoApiException Legado接口异常
   */
  public static void throwException(String errorMsg) throws LegadoApiException {
    throw new LegadoApiException(errorMsg);
  }

  /**
   * 显示错误弹出
   */
  public void showErrorAlert() {
    // 弹出错误对话框
    SwingUtilities.invokeLater(() -> {
      AlertMessagesUtil.showErrorDialog("错误", this.getMessage());
    });
  }
}
